import 'package:flutter/material.dart';
import 'package:flutter_study/flutter/_09%E8%B7%AF%E7%94%B1%E5%AF%BC%E8%88%AA/routes/Routes.dart';

void main() => runApp(MyApp());

//命名路由模块化与传值
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      // routes: routes,
      initialRoute: "/",
      onGenerateRoute: (RouteSettings settings) {
        // 统一处理
        final String name = settings.name;
        final Function pageContentBuilder = routes[name];
        print('pageContentBuilder=$pageContentBuilder');
        if (pageContentBuilder != null) {
          if (settings.arguments != null) {
            final Route route = MaterialPageRoute(
                builder: (context) =>
                    pageContentBuilder(context, arguments: settings.arguments));
            return route;
          } else {
            final Route route = MaterialPageRoute(
                builder: (context) => pageContentBuilder(context));
            return route;
          }
        }
        return null;
      },
    );
  }
}
